﻿Ext.define('yzmh.view.chapter.Edit', {
    extend: 'Ext.window.Window',
    alias: 'widget.chapteredit',

    title: '编辑章节',
    layout: 'fit',
    autoShow: true,
    width: 640,
    height: 420,

    initComponent: function () {
        
        this.items = [
            {
                xtype: 'form',
                border: true,
                frame: true,
                bodyPadding: '5 5 0',
                fieldDefaults: {
                    labelAlign: 'right',
                    labelWidth: 60,
                    anchor: '100%'
                },
                items: [{
                    xtype: 'hidden',
                    name: 'id'
                }, {
                    xtype: 'hidden',
                    name: 'cid'
                }, {
                    xtype: 'textfield',
                    name: 'zjmc',
                    fieldLabel: '章节名称'
                }, {
                    id:'tpadd-field',
                    xtype: 'trigger',
                    name: 'tpadd',
                    triggerClass: 'x-form-file-input',
                    fieldLabel: '章节图片地址',
                    onTriggerClick: function () {
                        var obj = this;
                        var finder = new CKFinder();
                        finder.basePath = '../';
                        finder.startupPath = Ext.util.Cookies.get("CKFinder:DynamicBaseUrl") + ':/' + decodeURI(obj.getValue());
                        finder.selectActionFunction = function(fileUrl, data, fileList) {
                            var arr = fileUrl.split('/');
                            var tpadd = "";
                            var tpurl = [];
                            for (var i = 3; i < arr.length - 1; i++) {
                                tpadd += arr[i] + "/";
                            }
                            for (var i = 0; i < fileList.length; i++) {
                                tpurl.push(fileList[i].url);
                            }
                            obj.setValue(decodeURI(tpadd));
                            obj.up("form").down("textareafield").setValue(tpurl.join('|'));
                            obj.up("form").down("#tps").setValue(tpurl.length);
                        };
                        finder.selectActionData = obj.getValue();
                        finder.popup();
                    }
                }, {
                    id: 'tps',
                    xtype: 'numberfield',
                    name: 'tps',
                    fieldLabel: '图片数目'
                }, {
                    xtype: 'textareafield',
                    name: 'tpurl',
                    fieldLabel: '章节图片',
                    height: 200
                }]
            }
        ];

        this.buttons = [
            {
                text: '保存',
                action: 'save'
            },
            {
                text: '取消',
                scope: this,
                handler: this.close
            }
        ];

        this.callParent(arguments);
    }
});
